package com.ebocy.hammer.game.service;

import com.ebocy.hammer.core.db.DaoManager;
import com.ebocy.hammer.core.db.IDao;
import com.ebocy.hammer.core.domain.Shop;

public class ShopService {
	private static IDao<Shop> shopDao = null;

	@SuppressWarnings("unchecked")
	private ShopService() {
		if (shopDao == null) {
			shopDao = DaoManager.getInstance().getDao(Shop.class);
		}
	}

	public static ShopService getInstance() {
		return new ShopService();
	}

	/**
	 * 获取商店物品详细
	 * 
	 * @param itemId
	 * @return
	 */
	public Shop findShopItem(long itemId) {
		Shop shopItem = shopDao.findOne("waresId", itemId);
		return shopItem;
	}

	/**
	 * 获取商店物品id
	 * 
	 * @param shopItem
	 * @param regex
	 * @return
	 */
	public int findShopItemId(Shop shopItem, String regex) {
		String goodsAndNumber = shopItem.getGoodsAndNumber();
		return Integer.parseInt(goodsAndNumber.split(regex)[0]);
	}

	/**
	 * 获取商店物品数量
	 * 
	 * @param shopItem
	 * @param regex
	 * @return
	 */
	public long findShopItemNum(Shop shopItem, String regex) {
		String goodsAndNumber = shopItem.getGoodsAndNumber();
		return Long.parseLong(goodsAndNumber.split(regex)[1]);
	}

	/**
	 * 获取商店物品售价
	 * 
	 * @param shopItem
	 * @param regex
	 * @param index
	 * @param regex2
	 * @return
	 */
	public int findShopPrice(Shop shopItem, String regex, int index, String regex2) {
		String expiresAndPrice = shopItem.getExpiresAndPrice();
		return Integer.valueOf(expiresAndPrice.split(regex)[index].split(regex2)[1]);
	}

	/**
	 * 获取商店物品期限
	 * 
	 * @param shopItem
	 * @param regex
	 * @param index
	 * @param regex2
	 * @return
	 */
	public short findShopExpires(Shop shopItem, String regex, int index, String regex2) {
		String expiresAndPrice = shopItem.getExpiresAndPrice();
		return Short.valueOf(expiresAndPrice.split(regex)[index].split(regex2)[0]);
	}

	public byte findShopKind(Shop shopItem) {
		return (byte) shopItem.getTabId();
	}

	public byte findShopCurrency(Shop shopItem) {
		return (byte) shopItem.getCurrency();
	}

}
